package Tian7
{
	import Tian7.event.AppEvent;
	import Tian7.layout.Detail;
	import Tian7.layout.Header;
	import Tian7.layout.Select;
	
	import flash.display.Loader;
	import flash.net.URLRequest;
	import flash.text.TextField;
	
	/**
	 * 布局 
	 * @author Kakera
	 * 
	 */
	public class Layout extends UI
	{
		private var select:Select;
		private var header:Header;
		private var detail:Detail;
		private var preloader:TextField;
		public function Layout() {

		}

		public override function update(width:int, height:int, data:*=null):void {
			super.update(width, height, data);
		}
		
		public function init ():void {
			trace("Layout.init");
			
			preloader = new TextField();
			preloader.text = "读取中";
			preloader.x = 
			preloader.y = 1;
			addChild(preloader);
			
			select = addChild( new Select() ) as Select;
			header = addChild( new Header() ) as Header;
			detail = addChild( new Detail() ) as Detail;
			
			header.addEventListener(AppEvent.CITY_CLICK, function (event:AppEvent):void {
				select.state = select.state.name == "open" ? "close" : "open";
			} );
			
			select.addEventListener(AppEvent.CITY_CLICK, function (event:AppEvent):void {
				header.data = event.data.currentCity;
				detail.data = event.data.currentCity;
			} );
			
			
		}
		
		public function renderData ():void {
			removeChild(preloader);
			
			select.data = data;
			dummylayout();
		}
		
		private function dummylayout ():void {
			var loader:Loader = new Loader();
			loader.load( new URLRequest("dummylayout.gif") );
			addChild(loader);
		}
	}
}